import './index.scss'
import { microCreateMinis } from '../../minis'

export default {
  name: 'micro-title-text',
  mixins: [microCreateMinis],
  props: {},
  data() {
    return {
      isGetChooseFeature: false, // 是否可以返回微页面
      dialogChoosePages: false, // 微页面弹窗
      tabActive: '0',
      formData: {
        tabSelect: 0,
        title: '标题内容',
        desc: '描述内容',
        linkUrl: '',
        title_size: 28,
        align: 'flex-start',
        titleColor: '#464646',
        descColor: '#C0C4CC',
        rightType: 1,
        rightTextColor: '#C0C4CC',
        rightIconColor: '#a17a51',
        bg_color: '#FFFFFF',
        specialFlag: false,
        height: 60,
        marginTop: '0',
        marginBottom: '0'
      },
      linkObj: {
        id: '',
        type: '',
        microType: '',
        microTitle: '',
        linkUrl: ''
      },
      commonCheckFieldRules: 'checkData', // 当前组件默认的规则判断函数
      mySelfCheckRules: 'mySelfCheckFun'// 我自己的验证规则函数  比如弹窗之类的
    }
  },
  watch: {},
  components: {
    chooseFeature: () => import('@/components/choose-feature/index.vue')
  },
  computed: {},
  mounted() {
  },
  methods: {
    // 选择微页面回调
    chooseChooseFeaturesFun($event) {
      console.log('$event', $event)
      const microTitle = $event.data.type === 0 && '系统页面' || $event.data.type === 1 && '功能页面' || $event.data.type === 2 && '商品详情'
      if ($event.data.type === 0) {
        this.setLinkInfo({
          id: $event.data.id,
          type: $event.data.type,
          title: $event.data.title,
          link: $event.data.path,
          microTitle: microTitle
        })
      } else {
        this.setLinkInfo({
          id: $event.data.id,
          type: $event.data.type,
          title: $event.data.title,
          link: $event.data.id,
          microTitle: microTitle
        })
      }
      this.dialogChoosePages = false
    },
    // 选择对应标题的列表页
    choosePage() {
      this.dialogChoosePages = true
    },
    /** 设置跳转信息*/
    setLinkInfo(obj) {
      this.linkObj.id = obj.id
      this.linkObj.type = obj.type
      this.linkObj.microType = obj.microTitle
      this.linkObj.microTitle = obj.title
      this.linkObj.linkUrl = obj.link
      this.formData.linkUrl = obj.link
      Object.assign(this.formData, this.linkObj)
    },
    resetBoderColor(type) {
      console.log(type, '0000000000')
      if (type === 1) {
        this.formData.titleColor = '#a17a51'
      } else if (type === 2) {
        this.formData.descColor = '#C0C4CC'
      } else if (type === 3) {
        this.formData.rightTextColor = '#C0C4CC'
      } else if (type === 4) {
        this.formData.rightIconColor = '#a17a51'
      } else if (type === 5) {
        this.formData.bg_color = '#FFFFFF'
      }
    },
    // 选择入口时触发
    changeEnter(val) {
      if (val === '0') {
        this.linkObj.id = ''
        this.linkObj.type = ''
        this.linkObj.microType = ''
        this.linkObj.microTitle = ''
        this.linkObj.linkUrl = ''
        this.formData.linkUrl = ''
      }
    },
    /**
     * 开始验证
     * */
    submit(vl) {
      this.myCheckResult(vl.status === 1)
    },
    checkData() {
      this.$nextTick(() => {
        if (this.$refs.formData) {
          this.$refs.formData.submit()
        } else {
          this.myCheckResult(true)
        }
      })
    },
    /** 弹窗*/
    mySelfCheckFun() { // 可以选择调用默认规则判断
      this.$nextTick(() => {
        if (this.$refs.formData) {
          this.$refs.formData.submit()
        }
      })
    }
  }
}
